// api/uploadApi.ts
import api from './config';

// === 上传投标文件 ===

/**
 * 上传一次海运投标文件
 */
export const createSeaBidForTender = async (
  tenderId: string,
  startingPort: string,
  file: File
): Promise<void> => {
  const formData = new FormData();
  formData.append('starting_port', startingPort);
  formData.append('file', file);

  await api.post(`/tenders/${tenderId}/bids/sea`, formData, {
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  });
};

/**
 * 上传一次管件投标文件
 */
export const createPipeBidForTender = async (
  tenderId: string,
  file: File
): Promise<void> => {
  const formData = new FormData();
  formData.append('file', file);

  await api.post(`/tenders/${tenderId}/bids/pipe`, formData, {
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  });
};

/**
 * 创建招标记录（上传招标文档）
 */
export const createTenderRecord = async (
  category: string,
  quarter: string,
  document: File
): Promise<{ id: string; category: string; quarter: string }> => {
  const formData = new FormData();
  formData.append('category', category);
  formData.append('quarter', quarter);
  formData.append('document', document);

  const response = await api.post(`/tenders/`, formData, {
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  });
  return response.data.tender;
};

export const createSteelBidForTender = async (
  tenderId: string,
  file: File
): Promise<void> => {
  const formData = new FormData();
  formData.append('file', file);

  await api.post(`/tenders/${tenderId}/bids/steel`, formData, {
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  });
};


export const createElectricalBidForTender = async (
  tenderId: string,
  file: File
): Promise<void> => {
  const formData = new FormData();
  formData.append('file', file);

  await api.post(`/tenders/${tenderId}/bids/electrical`, formData, {
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  });
};